package neusoft.example.com.yuejian06.Activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import neusoft.example.com.yuejian06.Bean.Course;
import neusoft.example.com.yuejian06.Model.CourseDetailModel;
import neusoft.example.com.yuejian06.R;
import neusoft.example.com.yuejian06.RetrofitListener;

public class CourseDetailActivity extends AppCompatActivity {

    private String course_id,club_id;
    private ImageView course_return;
    private TextView course_name,course_level,course_price,course_intro;
    private CourseDetailModel model;
    private RetrofitListener<Course> listener;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_course_detail);

        initView();
        listener();
        initEvents();

        model=new CourseDetailModel();
        model.getCourseById(course_id,listener);
    }


    public void initView(){
        course_id=getIntent().getStringExtra("course_id");
        course_return=findViewById(R.id.course_return);
        course_level=findViewById(R.id.course_level);
        course_price=findViewById(R.id.course_price);
        course_name=findViewById(R.id.course_name);
        course_intro=findViewById(R.id.course_intro);
    }
    public void listener(){
        listener=new RetrofitListener<Course>() {
            @Override
            public void onResponse(Course l) {
                course_name.setText(l.getCourse_name());
                course_level.setText("难度等级："+l.getCourse_level());
                course_price.setText("课程价格："+l.getCourse_price());
                course_intro.setText(l.getCourse_intro());
                club_id=l.getClub_id();
            }

            @Override
            public void onFail(String msg) {
                Toast.makeText(CourseDetailActivity.this, msg, Toast.LENGTH_SHORT).show();
            }
        };
    }

    public void initEvents(){
        course_return.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent=new Intent(CourseDetailActivity.this,ClubDetailActivity.class);
                intent.putExtra("club_id",club_id);
                startActivity(intent);
            }
        });
    }

}
